package com.xls.aclservice.controller;

import com.xls.aclservice.vo.SignupVo;
import com.xls.aclservice.entity.SysMenu;
import com.xls.aclservice.service.impl.LoginServiceImpl;
import com.xls.aclservice.vo.LoginVo;
import com.xls.commonutils.Result;
import com.xls.aclservice.vo.UserInfo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/acl/login")
@Api(value = "登录接口")
@Slf4j
public class LoginController {

    @Autowired
    private LoginServiceImpl loginService;

    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginVo loginVo) {
        String token = loginService.login(loginVo.getUsername(), loginVo.getPassword());
        return Result.success(token);
    }

    @GetMapping("/info")
    public Result<UserInfo> info() {
        UserInfo userInfo = loginService.info();
        return Result.success(userInfo);
    }

    @GetMapping("/menu")
    public Result<List<SysMenu>> menu() {
        List<SysMenu> sysMenus = loginService.getMenu();
        return Result.success(sysMenus);
    }

    @PostMapping("/logout")
    public Result<UserInfo> logout() {
        loginService.logout();
        return Result.success();
    }

    @GetMapping("/signup/getCode/{phone}")
    public Result<String> getCode(@PathVariable String phone) {
        String code = loginService.getCode(phone);
        return Result.success(code);
    }

    @PostMapping("/signup/signup")
    public Result<String> signup(@RequestBody SignupVo signupVo) {
        loginService.signup(signupVo);
        return Result.success();
    }

}
